<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
</head>
<body>
<div style="height: 20px"></div>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">用户管理</a>
        <a href="#">学校管理</a>
        <a href="#">添加学校</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<form  action=""  id="school" onsubmit="return false" style="width:500px">
    <input type="hidden" value="{$info.school_id}" name="id">
    <input type="hidden" value="{$info.phone}" name="r_phone">
    <div class="layui-form-item">
        <label class="layui-form-label">学校名称</label>
        <div class="layui-input-block">
            <input type="text" name="school_name" value="{$info.school_name}" id="school_name" placeholder="学校名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">登录账号</label>
        <div class="layui-input-block">
            <input type="text" name="login" id="login" value="{$info.login}" readonly placeholder="登录账号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系人</label>
        <div class="layui-input-block">
            <input type="text" name="phone_name" required value="{$info.phone_name}" id="phone_name" placeholder="学校名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系方式</label>
        <div class="layui-input-block">
            <input type="text" name="phone" required id="phone" value="{$info.phone}" placeholder="联系方式" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="text" name="email" id="email" value="{$info.email}" placeholder="邮箱" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">网址</label>
        <div class="layui-input-block">
            <input type="text" name="url" id="url" value="{$info.url}" placeholder="官网地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" >地址</label>
        <div class="layui-input-inline" style="display: inline-block" id="city">

        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">具体地址</label>
        <div class="layui-input-block">
            <textarea name="address" id="address" placeholder="具体地址" class="layui-textarea">{$info.address}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">合作时间</label>
        <div class="layui-input-block">
            <div class="layui-input-inline" style="width: 150px;">
                <input type="text" id="start" value="{$info.start}" name="start" placeholder="开始时间" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid">-</div>
            <div class="layui-input-inline" style="width: 150px;">
                <input type="text" id="end" value="{$info.end}" name="end" placeholder="结束时间" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">年级类别</label>
        <div class="layui-input-block" style="padding-top: 10px">
            {foreach $type as $key=>$val}
                <?php $temType = explode(',',$info['category']); ?>
                <input type="checkbox" {if in_array($val.type,$temType)} checked {/if} name="type[]" value="{$val.type}" title="{$val.grade_name}">{$val.grade_name}
            {/foreach}
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="update">立即保存</button>
            <button id="back" class="layui-btn layui-btn-primary">返回</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form','laydate'], function(){
        var form = layui.form;
        var laydate = layui.laydate;

        laydate.render({
            elem: '#end' //指定元素
        });
        laydate.render({
            elem: '#start' //指定元素
        });
    });
    $("#back").click(function () {
        window.history.go(-1);
    })
</script>
<script>
    //默认1级
    $(function(){
        load(1);
    });
    //城市级联
    function load(id){
        $.ajax({
            url:"{:url('/school/regionFind')}",
            data:"id="+id,
            type:"get",
            dataType:"json",
            success:function(data){
                if(data == null || data.length == 0){
                    return ;
                }
                var info = "<select name='province[]' ><option >-请选择-</option>";
                for(var i=0;i<data.length;i++){
                    info+='<option value=\"'+data[i].id+'\">';
                    info+= data[i].region_name;
                    info+='</option>';
                }
                info += "</select>";
                $(info).appendTo("#city").change(function(){
                    $(this).nextAll("select").remove();
                    if($(this).val() != ""){
                        load($(this).val());
                    }
                });
            }
        });
    }
</script>
<script>
    $("#update").click(function(){
        //邮箱正则
        var isEmail = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
        var phone_name = $("#phone_name").val();
        var email = $("#email").val();
        var url = $("#url").val();
        if(!phone_name){
            layer.msg('请输入联系人',{icon:5,time:2000});
            return;
        }
        if(url && IsURL(url) == false){
            layer.msg('请输入正确的网址',{icon:5,time:2000});
            return;
        }
        if(email && !isEmail.test(email)){
            layer.msg('请输入正确的邮箱',{icon:5,time:2000});
            return;
        }
        if(!end){
            layer.msg('请选择到期时间',{icon:5,time:2000});
            return;
        }
        $.ajax({
            url:"{:url('/school/schoolUpdate')}",
            type:"post",
            data:$("#school").serialize(),
            dataType:"json",
            success:function(res){
                if(res.code){
                    layer.msg(res.msg,{icon:1,time:2000},function(){
                        window.location.reload();
                    });
                    return;
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                    return;
                }
            }
        });
    });
    //是否是url
    function IsURL(str_url){
        var strRegex = '^((https|http|ftp|rtsp|mms)?://)'
                +'?(([0-9a-z_!~*().&=+$%-]+: )?[0-9a-z_!~*().&=+$%-]+@)?' //ftp的user@
                + '(([0-9]{1,3}.){3}[0-9]{1,3}' // IP形式的URL- 199.194.52.184
                + '|' // 允许IP和DOMAIN（域名）
                + '([0-9a-z_!~*()-]+.)*' // 域名- www.
                + '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].' // 二级域名
                + '[a-z]{2,6})' // first level domain- .com or .museum
                + '(:[0-9]{1,4})?' // 端口- :80
                + '((/?)|' // a slash isn't required if there is no file name
                + '(/[0-9a-z_!~*().;?:@&=+$,%#-]+)+/?)$';
        var re=new RegExp(strRegex);
        if (re.test(str_url)){
            return (true);
        }else{
            return (false);
        }
    }
</script>
</body>
</html>